/*
 * @Author: libing 9852442+liu-sheng-8667@user.noreply.gitee.com
 * @Date: 2024-04-12 21:07:59
 * @LastEditors: xuezhuangzhuang xzz6996@qq.com
 * @LastEditTime: 2025-07-03 11:57:03
 * @FilePath: \crm\pages\mixins\list-page.js
 * @Description: 混入-----滚动公用下拉列表分页
 */

const listPageMixins = {
  data() {
    return {
      list: [],
      status: "more",
      pagination: {
        current: 1,
        pageSize: 20,
        total: 0,
      },
      contentText: {
        contentdown: "查看更多",
        contentrefresh: "加载中",
        contentnomore: "没有更多",
      },
      defaltParams: {},
    };
  },
  methods: {
    // 获取数据
    async getList() {
      try {
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        const body = {
          current: this.pagination.current,
          size: this.pagination.pageSize,
        };
        if (this.customContactsPhone) {
          body.customContactsPhone = this.customContactsPhone;
        }
        if (this.custom) {
          body.custom = this.custom;
        }
        if (this.keyword) {
          body.name = this.keyword;
        }
        if (this.name) {
          body.name = this.name;
        }
        if (this.payStatus) {
          body.payStatus = this.payStatus;
        }
        if (this.orderStatus) {
          body.orderStatus = this.orderStatus;
        }
        if (this.phone) {
          body.phone = this.phone;
        }
        if (this.defaltParams) {
          Object.assign(body, this.defaltParams);
        }
        const res = await this.queryAPI(body);
        if (res) {
          let d = res.records || res.data?.records || [];
          if (this.dataFormat && typeof this.dataFormat === "function") {
            d = await this.dataFormat(d);
          }
          this.list = this.pagination.current == 1 ? [...d] : [...this.list, ...d];
          this.pagination.total = res.total ? res.total : res.data?.total;
        }
        this.status =
          this.list.length < this.pagination.total ? "more" : "noMore";
      } catch (error) {}
      setTimeout(() => {
        uni.hideLoading();
      }, 100);
    },
    // 查看更多
    loadmore() {
      if (this.list.length < this.pagination.total) {
        this.pagination.current += 1;
        this.getList();
      } else {
        this.status = "noMore";
      }
    },
    // 滚动到底部
    lower() {
      this.loadmore();
    },
    // 重置数据
    async upper() {
      this.pagination.current = 1;
      this.list = [];
      await this.getList();
    },
    // 跳转客户详情
    toCustomerInfoPage(item) {
      uni.navigateTo({
        url: "/pagescustomer/customer/customer-info?id=" + item.id,
      });
    },
    // 跳转跟进详情
    toFollowInfoPage(item) {
      uni.navigateTo({
        url: "/pagescustomer/customer/follow-records-info?id=" + item.id,
      });
    },
    // 跳转订单详情
    toOrderInfoPage(item) {
      uni.navigateTo({
        url: "/pagescustomer/customer/order-info?id=" + item.id,
      });
    },
  },
};

export default listPageMixins;
